/**
 * Copyright (c) 2007, Reliable Source, Inc. 
 * All Rights Reserved.
 */
package org.reliablesource.prism.ui.workbench.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.reliablesource.prism.ui.popup.actions.GenerateDocumentationAction;

/**
 * ExportAsDocumentationAction.java<br> 
 * Created on: Jul 25, 2007<br>
 *
 * @author Dennis Park 
 * 		<a href="mailto:dennis.park@gmail.com">dennis.park@gmail.com</a>
 *
 * @since 1.0
 *
 */
public class ExportAsDocumentationAction implements IWorkbenchWindowActionDelegate {

	private IWorkbenchWindow window;
	private IStructuredSelection selection;
	private IWorkbenchPart view;
	private GenerateDocumentationAction generateDocAction;
	public static String ID = "IPrismTutorial.Contribution.ExportDocumentationAction";
	
	
	
	public ExportAsDocumentationAction(){
		generateDocAction = new GenerateDocumentationAction();
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
	 */	
	public void dispose() {

	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
	 */
	public void init(IWorkbenchWindow _window) {
		window = _window;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
	public void run(IAction _action) {
		
		if(!_action.isEnabled())
			return;
		generateDocAction.run();
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
	public void selectionChanged(IAction _action, ISelection _selection) {
		selection = (IStructuredSelection) _selection;
		_action.setEnabled(false);
		
		if(null == _selection)
				return;

		boolean _enabled = generateDocAction.setSelection(_selection);
		_action.setEnabled(_enabled);
	}
	
	public String getId() {
		return ID;
	}


}
